package com.boatAnchorAssistant.service.controller.web;

import com.boatAnchorAssistant.pojo.param.authorization.AuthorizationParam;
import com.boatAnchorAssistant.pojo.param.authorization.GetAuthorizedTreeParam;
import com.boatAnchorAssistant.pojo.vo.authorization.AuthorizedVo;
import com.boatAnchorAssistant.pojo.vo.authorization.CurrentUserPageResourceVo;
import com.boatAnchorAssistant.pojo.vo.authorization.GetAuthorizedTreeVo;
import com.boatAnchorAssistant.service.service.in.AuthorizationService;
import javax.validation.Valid;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 *  web/授权
 * 【描 述】：
 * 【环 境】：J2SE 17
 * 【详 细】：
 *
 * @author 李松林
 * @version v1.0 2024/5/3 新建
 * @since 2024/5/3
 */
@RestController
@RequestMapping("/authorization/web")
public class AuthorizationWebController {

    /**
     *
     */
    private final AuthorizationService service;


    /**
     * 构造器
     *
     * @param service 授权服务
     */
    public AuthorizationWebController(AuthorizationService service) {
        this.service = service;
    }


    /**
     * 授权（禁用或授权、解除授权）
     *
     * @return
     */
    @PostMapping("/authorization")
    public ApiResult authorization(@RequestBody @Valid AuthorizationParam param) {
        service.authorization(param);
        return ApiResult.ok();
    }


    /**
     * 获取授权树
     *
     * @param param
     * @return
     */
    @PostMapping("/getAuthorizedTree")
    public ApiResult<GetAuthorizedTreeVo> getAuthorizedTree(@RequestBody @Valid GetAuthorizedTreeParam param) {
        GetAuthorizedTreeVo vo = service.getAuthorizedTree(param);
        return ApiResult.ok(vo);
    }


    /**
     * 获取当前用户的全部页面资源
     *
     * @return
     */
    @GetMapping("/getCurrentUserPageResource")
    public ApiResult<List<CurrentUserPageResourceVo>> getCurrentUserPageResource() {
        List<CurrentUserPageResourceVo> list = service.getCurrentUserPageResource();
        return ApiResult.ok(list);
    }



}
